//
//  Dictionary+ZJ.swift
//  ZJSwiftKit
//
//  Created by zyx on 2023/2/17.
//

import Foundation
/// Extend Dictionary with `zj` proxy.
//extension Dictionary: ZJPrefixProtocol {}
extension Dictionary: ZJMultiplePrefixProtocal {
    public typealias ZJT1 = Key
    public typealias ZJT2 = Value
}


public extension ZJMultiplePrefix where Base == [ZJT1 : ZJT2] {
    
    /// 转JSON字符串
    /// - Parameter opt: 用于写入JSON数据的选项。 默认为 []
    /// - Returns: jsonString maybe return ""
    func toJsonString(options opt: JSONSerialization.WritingOptions = []) -> String {
        
        if (!JSONSerialization.isValidJSONObject(base)) {
            print("无法解析出JSONString")
            return ""
        }
        if let data = try? JSONSerialization.data(withJSONObject: base, options: opt),
           let JSONString =  String.init(data: data, encoding: .utf8){
            return JSONString
        }
        return ""
    }
    
}

